﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import Events.*;

    public class GenericPopup extends SWFDialog {

        public static const SHARE:int = 1;
        public static const ACCEPT:int = 1;
        public static const OK:int = 1;
        public static const YES:int = 1;
        public static const CANCEL:int = 0;
        public static const NO:int = 0;
        public static const TYPE_OK:int = 0;
        public static const TYPE_ACCEPTCANCEL:int = 1;
        public static const TYPE_YESNO:int = 2;
        public static const TYPE_MODAL:int = 3;
        public static const TYPE_SAVESHARESAVE:int = 4;
        public static const TYPE_SHARECANCEL:int = 5;

        protected var m_window:MovieClip;
        protected var m_message:String;
        protected var m_type:int;
        protected var m_closeCallback:Function;
        protected var m_accept:GenericButton;
        protected var m_reject:GenericButton;
        protected var m_acceptTextName:String = "Accept";
        protected var m_cancelTextName:String = "Cancel";

        public function GenericPopup(_arg1:String, _arg2:int=0, _arg3:Function=null, _arg4:String="assets/dialogs/TI_GenericPopUp.swf"){
            m_dialogAsset = _arg4;
            super();
            this.m_type = _arg2;
            this.m_message = _arg1;
            if (this.m_type == TYPE_OK){
                this.m_acceptTextName = "Okay";
            } else {
                if (this.m_type == TYPE_YESNO){
                    this.m_acceptTextName = "Yes";
                    this.m_cancelTextName = "No";
                } else {
                    if (this.m_type == TYPE_ACCEPTCANCEL){
                        this.m_acceptTextName = "Accept";
                        this.m_cancelTextName = "Cancel";
                    } else {
                        if (this.m_type == TYPE_SHARECANCEL){
                            this.m_acceptTextName = "Share";
                            this.m_cancelTextName = "Cancel";
                        };
                    };
                };
            };
            if (_arg3 != null){
                this.m_closeCallback = _arg3;
                addEventListener(GenericPopupEvent.SELECTED, _arg3);
            };
        }
        protected static function getLocalizedString(_arg1:String, _arg2:Array=null):String{
            var _local3:Array = _arg1.split(":", 2);
            if (_local3.length == 1){
                _local3.splice(0, 0, "Dialogs");
            };
            _local3.push(_arg2);
            return (ZLoc.t.apply(null, _local3));
        }

        override protected function onLoadComplete():void{
            var _local1:Array = [];
            this.m_window = (m_loader.content as MovieClip);
            if (this.m_message != null){
                this.m_window.popupBox_mc.popupBox_tf.text = this.m_message;
            };
            this.setupButtons(this.m_window.popupBox_mc.accept_bt, this.m_window.popupBox_mc.cancel_bt);
            addChild(this.m_window);
        }
        protected function setupButtons(_arg1:MovieClip, _arg2:MovieClip):void{
            if (this.m_type == TYPE_OK){
                _arg2.visible = false;
                _arg1.x = ((this.m_window.width - _arg1.width) / 2);
            } else {
                if (this.m_type == TYPE_YESNO){
                    _arg1.visible = true;
                    _arg2.visible = true;
                } else {
                    if (this.m_type == TYPE_ACCEPTCANCEL){
                        _arg1.visible = true;
                        _arg2.visible = true;
                    } else {
                        if (this.m_type == TYPE_MODAL){
                            _arg1.visible = false;
                            _arg2.visible = false;
                        } else {
                            if (this.m_type == TYPE_SHARECANCEL){
                                _arg1.visible = true;
                                _arg2.visible = true;
                            };
                        };
                    };
                };
            };
            if (_arg1.visible){
                this.m_accept = new GenericButton(_arg1, this.onAccept);
                this.m_accept.text = getLocalizedString(this.m_acceptTextName);
            };
            if (_arg2.visible){
                this.m_reject = new GenericButton(_arg2, this.onCancel);
                this.m_reject.text = getLocalizedString(this.m_cancelTextName);
            };
        }
        public function setAcceptTextName(_arg1:String):void{
            this.m_acceptTextName = _arg1;
        }
        public function setCancelTextName(_arg1:String):void{
            this.m_cancelTextName = _arg1;
        }
        protected function onAccept(_arg1:MouseEvent):void{
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, YES));
            if (this.m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, this.m_closeCallback);
            };
            close();
        }
        protected function onCancel(_arg1:MouseEvent):void{
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, NO));
            if (this.m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, this.m_closeCallback);
            };
            close();
        }

    }
}//package Display 
